function prime(n) {
    if (n === 2) return true;

    if (n <= 1 || n % 2 === 0)
        return false;

    for (let c = 3; c * c <= n; c += 2)
        if (n % c === 0)
            return false;
    return true;
}

function sumPrimes(num) {
    let sum = num >= 2 ? 2 : 0;
    for (let n = 3; n <= num; n += 2)
        if (prime(n))
            sum += n;
    return sum;
}

console.log(sumPrimes(10));

